package com.meks.crmi.utils;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
 * base class if change support is needed.
 * @author mhager
 *
 */
public abstract class AbstractBean {
	
	/**
	 * inner change support where all change support methods are delegated to.
	 */
	private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

	/**
	 * @see {@link PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)}.
	 * @param listener 
	 */
	public final void addPropertyChangeListener(final PropertyChangeListener listener) {
		changeSupport.addPropertyChangeListener(listener);
	}
	/**
	 * @see {@link PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)}.
	 * @param propertyName 
	 * @param listener 
	 */
	public final void addPropertyChangeListener(final String propertyName,
			final PropertyChangeListener listener) {
		changeSupport.addPropertyChangeListener(propertyName, listener);
	}
	
	/**
	 * @see {@link PropertyChangeSupport#fireIndexedPropertyChange(String, int, boolean, boolean)}
	 * @param propertyName 
	 * @param index 
	 * @param oldValue 
	 * @param newValue 
	 */
	protected final void fireIndexedPropertyChange(final String propertyName, final int index,
			final boolean oldValue, final boolean newValue) {
		changeSupport.fireIndexedPropertyChange(propertyName, index, oldValue,
				newValue);
	}
	/**
	 * @see {@link PropertyChangeSupport#fireIndexedPropertyChange(String, int, int, int)}
	 * @param propertyName 
	 * @param index 
	 * @param oldValue 
	 * @param newValue 
	 */
	protected final void fireIndexedPropertyChange(final String propertyName, final int index,
			final int oldValue, final int newValue) {
		changeSupport.fireIndexedPropertyChange(propertyName, index, oldValue,
				newValue);
	}
	/**
	 * @see {@link PropertyChangeSupport#fireIndexedPropertyChange(String, int, Object, Object)}
	 * @param propertyName 
	 * @param index 
	 * @param oldValue 
	 * @param newValue 
	 */
	protected final void fireIndexedPropertyChange(final String propertyName, final int index,
			final Object oldValue, final Object newValue) {
		changeSupport.fireIndexedPropertyChange(propertyName, index, oldValue,
				newValue);
	}
	/**
	 * @see {@link PropertyChangeSupport#firePropertyChange(PropertyChangeEvent)}
	 * @param evt 
	 */
	protected final void firePropertyChange(final PropertyChangeEvent evt) {
		changeSupport.firePropertyChange(evt);
	}
	/**
	 * @see {@link PropertyChangeSupport#firePropertyChange(String, boolean, boolean)}
	 * @param propertyName 
	 * @param oldValue 
	 * @param newValue 
	 */
	protected final void firePropertyChange(final String propertyName, final boolean oldValue,
			final boolean newValue) {
		changeSupport.firePropertyChange(propertyName, oldValue, newValue);
	}
	/**
	 * @see {@link PropertyChangeSupport#firePropertyChange(String, int, int)}
	 * @param propertyName 
	 * @param oldValue 
	 * @param newValue 
	 */
	protected final void firePropertyChange(final String propertyName, final int oldValue,
			final int newValue) {
		changeSupport.firePropertyChange(propertyName, oldValue, newValue);
	}
	/**
	 * @see {@link PropertyChangeSupport#firePropertyChange(String, Object, Object)}
	 * @param propertyName 
	 * @param oldValue 
	 * @param newValue 
	 */
	protected final void firePropertyChange(final String propertyName, final Object oldValue,
			final Object newValue) {
		changeSupport.firePropertyChange(propertyName, oldValue, newValue);
	}
	/**
	 * @see {@link PropertyChangeSupport#getPropertyChangeListeners()}
	 * @return the registered change listeners
	 */
	protected final PropertyChangeListener[] getPropertyChangeListeners() {
		return changeSupport.getPropertyChangeListeners();
	}
	/**
	 * @see {@link PropertyChangeSupport#getPropertyChangeListeners(String)}
	 * @param propertyName 
	 * @return the registered change listeners
	 */
	protected final PropertyChangeListener[] getPropertyChangeListeners(
			final String propertyName) {
		return changeSupport.getPropertyChangeListeners(propertyName);
	}
	/**
	 * @see {@link PropertyChangeSupport#hasListeners(String)}
	 * @param propertyName 
	 * @return true if there are listeners
	 */
	public final boolean hasListeners(final String propertyName) {
		return changeSupport.hasListeners(propertyName);
	}
	/**
	 * @see {@link PropertyChangeSupport#removePropertyChangeListener(PropertyChangeListener)}
	 * @param listener 
	 */
	public final void removePropertyChangeListener(final PropertyChangeListener listener) {
		changeSupport.removePropertyChangeListener(listener);
	}
	/**
	 * @see {@link PropertyChangeSupport#removePropertyChangeListener(String, PropertyChangeListener)}
	 * @param propertyName 
	 * @param listener 
	 */
	public final void removePropertyChangeListener(final String propertyName,
			final PropertyChangeListener listener) {
		changeSupport.removePropertyChangeListener(propertyName, listener);
	}
	
	
}
